package db4oToOracle.obj1test;

import com.googlecode.datawander.connectors.Db4oUtil;
import com.googlecode.datawander.connectors.OracleConnector;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MarcinStachniuk
 */
public class SuperTask extends SuperSuperTask {

    private String superDescription = "sup desc";

    public static void saveAllRecords(SuperTask [] ssTasks) throws Exception {
        if(ssTasks != null) {
            java.sql.Connection conn = OracleConnector.getConnection();
            for(SuperTask o : ssTasks) {
                o.saveRecord(conn);
            }
        }
    }

    private void saveRecord(java.sql.Connection conn) throws java.sql.SQLException {
        String sql = "insert into \"SuperSuperTask\" (\"GENERATED_ID\", \"superDescription\", ) " +
                "values (?,?,?)";
        java.sql.PreparedStatement stmt = conn.prepareStatement(sql);
        stmt.setLong(1, getIdFromDb4o());
        stmt.setString(2, superDescription);

        stmt.setLong(3, super.getIdFromDb4o());

        stmt.executeUpdate();
        System.out.println("Zapisano Task id: "+getIdFromDb4o() + " name: " +
                superDescription + " id AppUser ");
    }

    public String getSuperDescription() {
        return superDescription;
    }

    public void setSuperDescription(String superDescription) {
        this.superDescription = superDescription;
    }

    /**
     * Pobiera id z db4o. Zakładam ze wynik bedzie inny niz zero, w przeciwnym
     * wypadku bedzie to obiekt ktorego nie bylo w db4o
     * @return
     */
    public long getIdFromDb4o() {
        com.db4o.ObjectContainer db = Db4oUtil.getObjectContainer();
        long id = db.ext().getID(this);
        return id;
    }
}
